package offer;

/**
 * <p>
 * 剑指 Offer 46. 把数字翻译成字符串
 * </p>
 *
 * @author xiaozuolin
 * @date 2021/9/26 9:33
 */
public class Offer46 {

    /**
     * a-0      b-1      c-2     d-3     e-4     f-5     g-6
     * h-7      i-8      j-9     k-10    l-11    m-12    n-13
     * o-14     p-15     q-16            r-17    s-18    t-19
     * u-20     v-21     w-22            x-23    y-24    z-25
     *
     * @param num
     * @return
     */
    public int translateNum(int num) {
        String s = String.valueOf(num);
        int[] dp = new int[s.length() + 1];
        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= s.length(); i++) {
            String tmp = s.substring(i - 2, i);
            if (tmp.compareTo("10") >= 0 && tmp.compareTo("25") <= 0) {
                dp[i] = dp[i - 1] + dp[i - 2];
            } else {
                dp[i] = dp[i - 1];
            }
        }
        return dp[s.length()];
    }

}
